package com.bis.ymyy.service.impl;

import com.bis.ymyy.common.exception.BusinessException;
import com.bis.ymyy.common.exception.EnumCode;
import com.bis.ymyy.entity.History;
import com.bis.ymyy.mapper.HistoryMapper;
import com.bis.ymyy.service.HistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class HistoryServiceImpl implements HistoryService {

    @Autowired
    private HistoryMapper historyMapper;

    @Override
    public List<History> getAll() {
        return historyMapper.getAll();
    }

    @Override
    public History getOne(String userName) {
        if (userName.equals("")){
            throw new BusinessException(EnumCode.E_100110);
        }
        return historyMapper.getOne(userName);
    }

    @Override
    public int addOne(History history) {
        if (history == null){
            throw new BusinessException(EnumCode.E_100108);
        }
        return historyMapper.addOne(history);
    }

    @Override
    public int updateOne(History history) {
        if (history == null){
            throw new BusinessException(EnumCode.E_100108);
        }
        return historyMapper.updateOne(history);
    }

    @Override
    public int deleteOne(String userName) {
        if (userName.equals("")){
            throw new BusinessException(EnumCode.E_100110);
        }
        return historyMapper.deleteOne(userName);
    }
}
